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

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

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

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

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

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

k = A("k")
b = B("b")
g = C("g")
a = D("a")
n = E("n")
c = F("c")

k.w = a
b.y = k
b.t = k
b.x = a
g.t = a
g.y = k
a.y = n
a.x = g
a.r = k
n.z = a
n.p = k
n.x = k
c.t = g
c.u = g
c.z = b
c.r = b
assert n.z.r.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: D = None
        self.txt = txt

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

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

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

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

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

k = A("k")
b = B("b")
g = C("g")
a = D("a")
n = E("n")
c = F("c")

k.w = a
b.y = k
b.t = k
b.x = a
g.t = a
g.y = k
a.y = n
a.x = g
a.r = k
n.z = a
n.p = k
n.x = k
c.t = g
c.u = g
c.z = b
c.r = b
assert n.z.r.w.txt == "a"