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

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

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

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

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

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

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

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

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

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

g.v = d
d.y = i
d.z = c
d.q = g
c.q = i
c.u = d
i.q = d
i.s = d
i.p = c
i.u = g
assert i.p.q.q.txt == "d"