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

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

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

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

i = A("i")
l = B("l")
b = C("b")
f = D("f")

i.q = f
l.s = i
l.u = i
l.v = b
l.r = f
b.x = i
b.u = i
f.q = l
assert b.u.q.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

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

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

i = A("i")
l = B("l")
b = C("b")
f = D("f")

i.q = f
l.s = i
l.u = i
l.v = b
l.r = f
b.x = i
b.u = i
f.q = l
assert b.u.q.q.r.txt == "f"