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

class B:
    def __init__(self, txt: str):
        self.p: D = None
        self.v: C = None
        self.u: D = None
        self.s: D = None
        self.txt = txt

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

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

e = A("e")
a = B("a")
n = C("n")
b = D("b")

e.r = b
a.p = b
a.u = b
a.s = b
a.v = n
n.s = e
n.y = e
n.x = e
b.x = e
b.v = a
b.t = a
b.y = a
assert n.s.r.x.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.p: D = None
        self.v: C = None
        self.u: D = None
        self.s: D = None
        self.txt = txt

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

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

e = A("e")
a = B("a")
n = C("n")
b = D("b")

e.r = b
a.p = b
a.u = b
a.s = b
a.v = n
n.s = e
n.y = e
n.x = e
b.x = e
b.v = a
b.t = a
b.y = a
assert n.s.r.x.r.txt == "b"