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

g = A("g")
h = B("h")
j = B("j")
n = A("n")
m = B("m")
l = A("l")
d = B("d")
e = B("e")
i = B("i")

g.u = l
h.u = i
h.z = j
j.u = d
j.z = e
n.u = l
m.u = h
m.z = d
l.u = g
d.u = e
d.z = i
e.u = m
e.z = j
i.u = j
i.z = e
assert g.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.u: B = None
        self.z: B = None
        self.txt = txt

g = A("g")
h = B("h")
j = B("j")
n = A("n")
m = B("m")
l = A("l")
d = B("d")
e = B("e")
i = B("i")

g.u = l
h.u = i
h.z = j
j.u = d
j.z = e
n.u = l
m.u = h
m.z = d
l.u = g
d.u = e
d.z = i
e.u = m
e.z = j
i.u = j
i.z = e
assert g.u.u.u.u.u.u.u.u.txt == "g"