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

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

a = A("a")
k = B("k")
n = A("n")
g = B("g")
f = A("f")
i = B("i")
m = A("m")
d = A("d")
h = B("h")

a.u = h
a.t = k
k.r = g
n.u = k
n.t = h
g.r = i
f.u = i
f.t = g
i.r = g
m.u = i
m.t = g
d.u = i
d.t = i
h.r = g
assert a.u.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.t: B = None
        self.txt = txt

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

a = A("a")
k = B("k")
n = A("n")
g = B("g")
f = A("f")
i = B("i")
m = A("m")
d = A("d")
h = B("h")

a.u = h
a.t = k
k.r = g
n.u = k
n.t = h
g.r = i
f.u = i
f.t = g
i.r = g
m.u = i
m.t = g
d.u = i
d.t = i
h.r = g
assert a.u.r.r.r.txt == "g"