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

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

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

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

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

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

e.x = c
b.q = a
b.r = a
a.q = b
a.r = b
c.q = a
c.r = a
j.q = c
j.r = b
assert j.q.r.r.q.r.txt == "b"