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

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

class C:
    def __init__(self, txt: str):
        self.p: D = None
        self.txt = txt

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

k = A("k")
d = B("d")
l = C("l")
g = D("g")

k.r = d
k.z = g
d.y = l
l.p = g
g.u = k
g.q = k
g.t = l
assert d.y.p.q.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.z: D = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.p: D = None
        self.txt = txt

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

k = A("k")
d = B("d")
l = C("l")
g = D("g")

k.r = d
k.z = g
d.y = l
l.p = g
g.u = k
g.q = k
g.t = l
assert d.y.p.q.txt == "k"