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

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

h = A("h")
j = B("j")
b = B("b")
e = A("e")
a = A("a")

h.q = j
j.v = b
j.r = a
b.v = j
b.r = e
e.q = b
a.q = j
assert a.q.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

h = A("h")
j = B("j")
b = B("b")
e = A("e")
a = A("a")

h.q = j
j.v = b
j.r = a
b.v = j
b.r = e
e.q = b
a.q = j
assert a.q.v.v.v.txt == "b"