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

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

i = A("i")
g = B("g")
e = A("e")
c = B("c")
a = A("a")
d = B("d")
h = A("h")

i.o = e
i.p = e
g.u = d
g.t = d
e.o = a
e.p = h
c.u = g
c.t = g
a.o = h
a.p = i
d.u = c
d.t = g
h.o = e
h.p = e
assert i.o.p.p.o.p.p.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.p: A = None
        self.txt = txt

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

i = A("i")
g = B("g")
e = A("e")
c = B("c")
a = A("a")
d = B("d")
h = A("h")

i.o = e
i.p = e
g.u = d
g.t = d
e.o = a
e.p = h
c.u = g
c.t = g
a.o = h
a.p = i
d.u = c
d.t = g
h.o = e
h.p = e
assert i.o.p.p.o.p.p.o.txt == "a"