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

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

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

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

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

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

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

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

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

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

a.r = l
m.u = d
m.x = a
d.y = a
j.q = c
j.w = l
j.r = a
j.v = n
n.u = d
n.x = c
l.q = c
l.r = c
l.w = j
l.v = m
c.r = j
assert l.v.u.y.r.w.r.r.txt == "l"