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

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

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

d = A("d")
i = B("i")
j = C("j")
c = C("c")
b = A("b")

d.x = b
d.u = b
i.p = d
i.u = b
j.z = d
j.t = c
j.u = c
c.z = b
c.t = j
c.u = j
b.x = d
b.u = d
assert b.x.u.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.u: A = None
        self.txt = txt

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

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

d = A("d")
i = B("i")
j = C("j")
c = C("c")
b = A("b")

d.x = b
d.u = b
i.p = d
i.u = b
j.z = d
j.t = c
j.u = c
c.z = b
c.t = j
c.u = j
b.x = d
b.u = d
assert b.x.u.x.txt == "d"