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

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

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

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

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

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

b.q = e
j.q = e
j.x = e
e.q = j
e.x = j
h.q = e
assert j.x.x.q.x.txt == "j"