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

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

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

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

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

class F:
    def __init__(self, txt: str):
        self.v: E = None
        self.x: B = None
        self.txt = txt

k = A("k")
f = B("f")
g = C("g")
m = D("m")
n = E("n")
b = F("b")
j = C("j")
c = A("c")

k.z = m
f.x = g
f.y = g
g.z = f
m.y = j
n.v = m
b.v = n
b.x = f
j.z = f
c.z = m
assert m.y.z.x.z.x.txt == "
class A:
    def __init__(self, txt: str):
        self.z: D = None
        self.txt = txt

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

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

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

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

class F:
    def __init__(self, txt: str):
        self.v: E = None
        self.x: B = None
        self.txt = txt

k = A("k")
f = B("f")
g = C("g")
m = D("m")
n = E("n")
b = F("b")
j = C("j")
c = A("c")

k.z = m
f.x = g
f.y = g
g.z = f
m.y = j
n.v = m
b.v = n
b.x = f
j.z = f
c.z = m
assert m.y.z.x.z.x.txt == "g"