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

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

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

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

d = A("d")
c = B("c")
g = C("g")
a = D("a")

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

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

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

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

d = A("d")
c = B("c")
g = C("g")
a = D("a")

d.t = g
d.q = g
c.r = a
g.p = d
a.t = d
a.y = d
a.s = d
a.x = c
assert g.p.t.p.q.txt == "g"