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

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

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

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

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

j.u = l
j.x = i
l.y = i
i.x = b
b.r = i
b.q = l
b.p = l
assert j.x.x.r.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.x: C = None
        self.txt = txt

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

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

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

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

j.u = l
j.x = i
l.y = i
i.x = b
b.r = i
b.q = l
b.p = l
assert j.x.x.r.txt == "i"