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

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

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

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

c = A("c")
d = B("d")
a = C("a")
n = D("n")
i = D("i")

c.p = a
c.y = a
d.v = a
d.q = c
a.t = n
n.p = c
n.r = a
i.p = c
i.r = a
assert c.p.t.r.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.y: C = None
        self.txt = txt

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

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

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

c = A("c")
d = B("d")
a = C("a")
n = D("n")
i = D("i")

c.p = a
c.y = a
d.v = a
d.q = c
a.t = n
n.p = c
n.r = a
i.p = c
i.r = a
assert c.p.t.r.txt == "a"