class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.v: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

e = A("e")
j = B("j")
f = B("f")
g = A("g")

e.q = g
e.v = f
j.v = e
f.v = g
g.q = e
g.v = j
assert g.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.v: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

e = A("e")
j = B("j")
f = B("f")
g = A("g")

e.q = g
e.v = f
j.v = e
f.v = g
g.q = e
g.v = j
assert g.v.v.v.txt == "f"