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

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

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

g = A("g")
d = B("d")
l = C("l")
n = B("n")
j = B("j")

g.q = l
g.t = l
d.z = l
d.v = l
d.x = g
l.q = d
l.w = g
l.z = g
n.z = l
n.v = l
n.x = g
j.z = l
j.v = l
j.x = g
assert d.x.t.z.t.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.t: C = None
        self.txt = txt

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

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

g = A("g")
d = B("d")
l = C("l")
n = B("n")
j = B("j")

g.q = l
g.t = l
d.z = l
d.v = l
d.x = g
l.q = d
l.w = g
l.z = g
n.z = l
n.v = l
n.x = g
j.z = l
j.v = l
j.x = g
assert d.x.t.z.t.txt == "l"