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

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

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

f.x = c
f.y = m
e.o = h
h.o = i
m.x = f
m.y = d
b.o = h
c.x = m
c.y = m
i.o = e
d.x = f
d.y = c
k.o = h
assert k.o.o.o.o.o.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.y: A = None
        self.txt = txt

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

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

f.x = c
f.y = m
e.o = h
h.o = i
m.x = f
m.y = d
b.o = h
c.x = m
c.y = m
i.o = e
d.x = f
d.y = c
k.o = h
assert k.o.o.o.o.o.o.o.o.o.txt == "e"