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

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

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

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

f = A("f")
j = B("j")
d = C("d")
g = D("g")

f.r = g
f.x = g
f.z = d
j.p = f
j.r = g
j.u = g
j.q = d
d.s = j
d.z = j
g.x = f
assert f.r.x.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.x: D = None
        self.z: C = None
        self.txt = txt

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

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

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

f = A("f")
j = B("j")
d = C("d")
g = D("g")

f.r = g
f.x = g
f.z = d
j.p = f
j.r = g
j.u = g
j.q = d
d.s = j
d.z = j
g.x = f
assert f.r.x.r.x.txt == "f"