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

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

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

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

a = A("a")
g = B("g")
i = C("i")
c = D("c")

a.q = g
g.q = a
g.z = a
g.v = i
i.y = c
i.q = g
i.v = a
i.s = a
c.s = i
assert c.s.v.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

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

a = A("a")
g = B("g")
i = C("i")
c = D("c")

a.q = g
g.q = a
g.z = a
g.v = i
i.y = c
i.q = g
i.v = a
i.s = a
c.s = i
assert c.s.v.q.txt == "g"