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

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

class C:
    def __init__(self, txt: str):
        self.t: B = None
        self.p: B = None
        self.txt = txt

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

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

m.v = d
m.z = c
m.y = c
m.x = f
c.u = g
c.p = g
c.r = m
f.t = c
f.p = d
g.p = f
k.v = d
k.z = d
k.x = f
k.y = c
d.u = g
d.p = g
d.r = k
assert k.v.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.z: B = None
        self.x: C = None
        self.y: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.t: B = None
        self.p: B = None
        self.txt = txt

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

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

m.v = d
m.z = c
m.y = c
m.x = f
c.u = g
c.p = g
c.r = m
f.t = c
f.p = d
g.p = f
k.v = d
k.z = d
k.x = f
k.y = c
d.u = g
d.p = g
d.r = k
assert k.v.p.p.txt == "f"