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

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

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

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

f = A("f")
c = B("c")
a = C("a")
l = D("l")

f.u = l
c.q = a
c.z = a
a.r = c
a.x = f
l.u = c
l.r = f
assert l.u.q.x.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.txt = txt

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

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

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

f = A("f")
c = B("c")
a = C("a")
l = D("l")

f.u = l
c.q = a
c.z = a
a.r = c
a.x = f
l.u = c
l.r = f
assert l.u.q.x.u.txt == "l"