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

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

g = A("g")
f = B("f")
a = B("a")
n = A("n")

g.u = a
f.r = a
f.t = g
a.r = f
a.t = n
n.u = a
assert n.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.r: B = None
        self.t: A = None
        self.txt = txt

g = A("g")
f = B("f")
a = B("a")
n = A("n")

g.u = a
f.r = a
f.t = g
a.r = f
a.t = n
n.u = a
assert n.u.t.u.txt == "a"