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

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

h = A("h")
i = B("i")
a = A("a")
k = A("k")
e = B("e")
m = B("m")
j = B("j")
c = A("c")

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

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

h = A("h")
i = B("i")
a = A("a")
k = A("k")
e = B("e")
m = B("m")
j = B("j")
c = A("c")

h.x = c
i.o = e
i.x = e
a.x = c
k.x = h
e.o = i
e.x = i
m.o = i
m.x = j
j.o = e
j.x = i
c.x = a
assert c.x.x.x.x.x.x.x.x.txt == "c"