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

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

d = A("d")
j = B("j")
k = B("k")
g = B("g")
a = A("a")
b = B("b")
h = B("h")
l = A("l")

d.o = l
j.u = g
k.u = b
g.u = k
a.o = d
b.u = g
h.u = k
l.o = d
assert g.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

d = A("d")
j = B("j")
k = B("k")
g = B("g")
a = A("a")
b = B("b")
h = B("h")
l = A("l")

d.o = l
j.u = g
k.u = b
g.u = k
a.o = d
b.u = g
h.u = k
l.o = d
assert g.u.u.u.txt == "g"