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

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

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

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

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

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

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

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

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

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

j.p = b
j.u = k
j.y = i
i.x = j
b.u = j
k.q = j
k.o = j
assert k.q.p.u.txt == "j"