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

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

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

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

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

m.x = i
g.z = a
f.y = k
f.x = a
f.v = a
f.p = i
a.y = c
a.x = k
c.y = g
c.x = a
c.v = a
c.p = m
k.z = a
i.x = m
assert g.z.y.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

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

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

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

m.x = i
g.z = a
f.y = k
f.x = a
f.v = a
f.p = i
a.y = c
a.x = k
c.y = g
c.x = a
c.v = a
c.p = m
k.z = a
i.x = m
assert g.z.y.p.txt == "m"