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

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

a = A("a")
n = B("n")
b = B("b")
d = A("d")
f = A("f")
e = B("e")
j = B("j")

a.u = f
a.s = f
n.t = e
b.t = j
d.u = f
d.s = f
f.u = a
f.s = d
e.t = j
j.t = b
assert n.t.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.s: A = None
        self.txt = txt

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

a = A("a")
n = B("n")
b = B("b")
d = A("d")
f = A("f")
e = B("e")
j = B("j")

a.u = f
a.s = f
n.t = e
b.t = j
d.u = f
d.s = f
f.u = a
f.s = d
e.t = j
j.t = b
assert n.t.t.t.t.txt == "j"