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

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

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

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

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

i.y = n
m.y = i
m.p = i
m.v = n
g.q = n
g.u = a
n.s = i
n.u = c
n.v = m
a.y = n
c.y = n
assert n.v.v.s.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.txt = txt

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

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

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

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

i.y = n
m.y = i
m.p = i
m.v = n
g.q = n
g.u = a
n.s = i
n.u = c
n.v = m
a.y = n
c.y = n
assert n.v.v.s.y.txt == "n"