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

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

d = A("d")
b = B("b")
k = A("k")

d.t = k
d.p = b
b.x = k
b.u = k
k.t = d
k.p = b
assert b.u.t.p.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.p: B = None
        self.txt = txt

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

d = A("d")
b = B("b")
k = A("k")

d.t = k
d.p = b
b.x = k
b.u = k
k.t = d
k.p = b
assert b.u.t.p.txt == "b"