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

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

c = A("c")
f = B("f")
e = B("e")
d = A("d")
j = A("j")
g = B("g")
b = B("b")
i = A("i")
k = B("k")
m = A("m")

c.o = d
f.o = d
e.o = m
d.o = j
j.o = m
g.o = c
b.o = c
i.o = m
k.o = i
m.o = d
assert e.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.o: A = None
        self.txt = txt

c = A("c")
f = B("f")
e = B("e")
d = A("d")
j = A("j")
g = B("g")
b = B("b")
i = A("i")
k = B("k")
m = A("m")

c.o = d
f.o = d
e.o = m
d.o = j
j.o = m
g.o = c
b.o = c
i.o = m
k.o = i
m.o = d
assert e.o.o.o.o.o.o.o.txt == "m"