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

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

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

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

n = A("n")
g = B("g")
d = C("d")
i = D("i")
b = D("b")

n.r = b
n.v = g
n.q = d
g.v = b
d.z = n
i.z = n
b.z = n
assert g.v.z.v.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.v: B = None
        self.q: C = None
        self.txt = txt

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

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

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

n = A("n")
g = B("g")
d = C("d")
i = D("i")
b = D("b")

n.r = b
n.v = g
n.q = d
g.v = b
d.z = n
i.z = n
b.z = n
assert g.v.z.v.txt == "g"