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

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

i = A("i")
d = B("d")
e = A("e")
j = B("j")
a = B("a")
b = A("b")
g = A("g")

i.o = b
d.q = j
d.r = a
e.o = b
j.q = a
j.r = d
a.q = d
a.r = d
b.o = e
g.o = b
assert d.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

i = A("i")
d = B("d")
e = A("e")
j = B("j")
a = B("a")
b = A("b")
g = A("g")

i.o = b
d.q = j
d.r = a
e.o = b
j.q = a
j.r = d
a.q = d
a.r = d
b.o = e
g.o = b
assert d.q.q.q.q.txt == "j"