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

class B:
    def __init__(self, txt: str):
        self.q: A = None
        self.v: C = None
        self.txt = txt

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

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

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

class B:
    def __init__(self, txt: str):
        self.q: A = None
        self.v: C = None
        self.txt = txt

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

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

d.x = j
d.z = j
d.r = k
f.q = d
f.v = g
k.s = f
k.v = d
g.s = f
g.v = j
j.x = d
j.z = d
j.r = g
assert d.x.r.s.q.txt == "d"