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

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

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

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

f = A("f")
k = B("k")
m = C("m")
e = D("e")
n = B("n")
d = D("d")
a = D("a")
g = D("g")
i = B("i")

f.v = m
f.x = d
f.y = a
k.y = i
k.p = f
k.z = m
m.v = f
m.p = f
m.r = g
m.w = e
e.v = f
n.y = i
n.p = f
n.z = m
d.v = f
a.v = f
g.v = f
i.y = n
i.p = f
i.z = m
assert a.v.x.v.y.v.y.v.x.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.x: D = None
        self.y: D = None
        self.txt = txt

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

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

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

f = A("f")
k = B("k")
m = C("m")
e = D("e")
n = B("n")
d = D("d")
a = D("a")
g = D("g")
i = B("i")

f.v = m
f.x = d
f.y = a
k.y = i
k.p = f
k.z = m
m.v = f
m.p = f
m.r = g
m.w = e
e.v = f
n.y = i
n.p = f
n.z = m
d.v = f
a.v = f
g.v = f
i.y = n
i.p = f
i.z = m
assert a.v.x.v.y.v.y.v.x.v.txt == "f"