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

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

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

g.u = d
a.x = c
n.u = h
c.x = a
f.x = c
e.u = n
h.u = d
d.u = e
assert d.u.u.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.x: B = None
        self.txt = txt

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

g.u = d
a.x = c
n.u = h
c.x = a
f.x = c
e.u = n
h.u = d
d.u = e
assert d.u.u.u.u.u.u.u.u.txt == "d"