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

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

a = A("a")
k = B("k")
c = B("c")
e = B("e")
d = A("d")
m = B("m")
g = B("g")
n = A("n")

a.o = d
k.u = d
c.u = a
e.u = n
d.o = n
m.u = n
g.u = n
n.o = a
assert e.u.o.o.o.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

a = A("a")
k = B("k")
c = B("c")
e = B("e")
d = A("d")
m = B("m")
g = B("g")
n = A("n")

a.o = d
k.u = d
c.u = a
e.u = n
d.o = n
m.u = n
g.u = n
n.o = a
assert e.u.o.o.o.o.o.o.o.txt == "a"