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.p: B = None
        self.txt = txt

g = A("g")
a = B("a")
k = A("k")
f = A("f")
i = B("i")
l = A("l")
c = B("c")
h = A("h")
j = A("j")

g.x = j
a.o = c
a.p = c
k.x = f
f.x = l
i.o = c
i.p = a
l.x = h
c.o = i
c.p = a
h.x = g
j.x = l
assert h.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.p: B = None
        self.txt = txt

g = A("g")
a = B("a")
k = A("k")
f = A("f")
i = B("i")
l = A("l")
c = B("c")
h = A("h")
j = A("j")

g.x = j
a.o = c
a.p = c
k.x = f
f.x = l
i.o = c
i.p = a
l.x = h
c.o = i
c.p = a
h.x = g
j.x = l
assert h.x.x.x.x.txt == "h"