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

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

f = A("f")
n = B("n")
d = A("d")
i = B("i")
e = A("e")
c = B("c")
h = A("h")
l = B("l")
a = B("a")
j = A("j")

f.t = n
f.r = h
n.u = e
d.t = i
d.r = j
i.u = j
e.t = a
e.r = h
c.u = e
h.t = i
h.r = j
l.u = f
a.u = h
j.t = c
j.r = h
assert f.t.u.r.t.u.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.r: A = None
        self.txt = txt

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

f = A("f")
n = B("n")
d = A("d")
i = B("i")
e = A("e")
c = B("c")
h = A("h")
l = B("l")
a = B("a")
j = A("j")

f.t = n
f.r = h
n.u = e
d.t = i
d.r = j
i.u = j
e.t = a
e.r = h
c.u = e
h.t = i
h.r = j
l.u = f
a.u = h
j.t = c
j.r = h
assert f.t.u.r.t.u.txt == "j"