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

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

f = A("f")
c = B("c")
d = B("d")
a = B("a")
e = A("e")
i = B("i")

f.o = d
f.q = e
c.q = d
d.q = c
a.q = c
e.o = c
e.q = f
i.q = d
assert e.o.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.q: A = None
        self.txt = txt

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

f = A("f")
c = B("c")
d = B("d")
a = B("a")
e = A("e")
i = B("i")

f.o = d
f.q = e
c.q = d
d.q = c
a.q = c
e.o = c
e.q = f
i.q = d
assert e.o.q.q.q.txt == "d"