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

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

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

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

d = A("d")
l = B("l")
h = C("h")
g = D("g")

d.u = g
d.x = l
l.r = h
h.q = l
g.y = l
assert l.r.q.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.x: B = None
        self.txt = txt

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

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

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

d = A("d")
l = B("l")
h = C("h")
g = D("g")

d.u = g
d.x = l
l.r = h
h.q = l
g.y = l
assert l.r.q.r.q.txt == "l"