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

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

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

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

l = A("l")
h = B("h")
k = C("k")
f = D("f")
e = A("e")

l.r = e
h.u = k
h.v = f
h.q = f
h.x = f
k.v = f
k.x = f
k.y = f
k.s = e
f.v = h
e.r = l
assert e.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

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

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

l = A("l")
h = B("h")
k = C("k")
f = D("f")
e = A("e")

l.r = e
h.u = k
h.v = f
h.q = f
h.x = f
k.v = f
k.x = f
k.y = f
k.s = e
f.v = h
e.r = l
assert e.r.r.r.txt == "l"