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

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

j = A("j")
a = B("a")
d = A("d")
i = A("i")
b = B("b")
n = A("n")

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

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

j = A("j")
a = B("a")
d = A("d")
i = A("i")
b = B("b")
n = A("n")

j.u = a
j.r = i
a.u = n
a.t = b
d.u = b
d.r = n
i.u = b
i.r = j
b.u = j
b.t = a
n.u = a
n.r = d
assert i.u.u.u.t.txt == "b"