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

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

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

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

f = A("f")
n = B("n")
l = C("l")
d = D("d")

f.p = n
n.q = l
n.t = f
n.s = f
n.r = d
l.r = f
l.y = f
d.x = f
assert f.p.q.y.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

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

f = A("f")
n = B("n")
l = C("l")
d = D("d")

f.p = n
n.q = l
n.t = f
n.s = f
n.r = d
l.r = f
l.y = f
d.x = f
assert f.p.q.y.txt == "f"