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

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

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

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

l = A("l")
n = B("n")
d = C("d")
b = D("b")
j = C("j")
c = C("c")
m = A("m")

l.v = b
n.r = b
n.t = b
d.r = m
b.y = l
b.p = l
b.x = n
b.u = d
j.r = l
c.r = l
m.v = b
assert d.r.v.y.v.x.r.txt == "
class A:
    def __init__(self, txt: str):
        self.v: D = None
        self.txt = txt

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

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

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

l = A("l")
n = B("n")
d = C("d")
b = D("b")
j = C("j")
c = C("c")
m = A("m")

l.v = b
n.r = b
n.t = b
d.r = m
b.y = l
b.p = l
b.x = n
b.u = d
j.r = l
c.r = l
m.v = b
assert d.r.v.y.v.x.r.txt == "b"