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

class B:
    def __init__(self, txt: str):
        self.t: A = None
        self.z: A = None
        self.txt = txt

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

d.u = h
h.t = c
h.z = d
i.t = l
i.z = j
j.u = i
m.t = j
m.z = l
l.u = g
g.t = c
g.z = d
f.u = h
k.t = j
k.z = j
c.u = i
assert j.u.t.u.t.u.t.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: A = None
        self.z: A = None
        self.txt = txt

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

d.u = h
h.t = c
h.z = d
i.t = l
i.z = j
j.u = i
m.t = j
m.z = l
l.u = g
g.t = c
g.z = d
f.u = h
k.t = j
k.z = j
c.u = i
assert j.u.t.u.t.u.t.u.txt == "g"