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

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

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

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

k = A("k")
m = B("m")
e = C("e")
g = D("g")
n = B("n")

k.x = e
k.u = e
k.r = n
m.w = k
m.x = g
e.u = n
e.x = n
e.y = g
e.r = m
g.u = e
g.x = k
n.w = k
n.x = g
assert k.r.w.u.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.u: C = None
        self.r: B = None
        self.txt = txt

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

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

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

k = A("k")
m = B("m")
e = C("e")
g = D("g")
n = B("n")

k.x = e
k.u = e
k.r = n
m.w = k
m.x = g
e.u = n
e.x = n
e.y = g
e.r = m
g.u = e
g.x = k
n.w = k
n.x = g
assert k.r.w.u.txt == "e"