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

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

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

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

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

k.r = f
f.x = n
g.r = f
g.u = f
g.z = n
g.w = k
n.v = f
n.u = f
n.x = k
c.r = f
c.u = f
c.z = n
c.w = k
a.r = f
a.u = f
a.z = n
a.w = k
assert k.r.x.x.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

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

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

k.r = f
f.x = n
g.r = f
g.u = f
g.z = n
g.w = k
n.v = f
n.u = f
n.x = k
c.r = f
c.u = f
c.z = n
c.w = k
a.r = f
a.u = f
a.z = n
a.w = k
assert k.r.x.x.r.txt == "f"