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

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

i = A("i")
g = B("g")
k = A("k")
a = B("a")
f = B("f")

i.o = k
i.q = k
g.o = a
g.u = a
k.o = i
k.q = i
a.o = g
a.u = f
f.o = a
f.u = a
assert f.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.q: A = None
        self.txt = txt

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

i = A("i")
g = B("g")
k = A("k")
a = B("a")
f = B("f")

i.o = k
i.q = k
g.o = a
g.u = a
k.o = i
k.q = i
a.o = g
a.u = f
f.o = a
f.u = a
assert f.o.o.o.txt == "a"