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

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

c = A("c")
g = B("g")
h = A("h")
j = A("j")
d = B("d")
a = A("a")
b = B("b")
f = B("f")

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

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

c = A("c")
g = B("g")
h = A("h")
j = A("j")
d = B("d")
a = A("a")
b = B("b")
f = B("f")

c.u = j
g.u = d
h.u = c
j.u = c
d.u = b
a.u = j
b.u = f
f.u = b
assert c.u.u.u.u.u.u.txt == "c"