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

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

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

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

g = A("g")
i = B("i")
l = C("l")
m = D("m")
c = A("c")
b = B("b")

g.p = m
g.x = m
g.t = c
i.x = b
i.q = m
l.p = i
m.s = l
c.p = m
c.x = m
c.t = g
b.x = i
b.q = m
assert l.p.x.q.s.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.t: A = None
        self.x: D = None
        self.txt = txt

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

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

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

g = A("g")
i = B("i")
l = C("l")
m = D("m")
c = A("c")
b = B("b")

g.p = m
g.x = m
g.t = c
i.x = b
i.q = m
l.p = i
m.s = l
c.p = m
c.x = m
c.t = g
b.x = i
b.q = m
assert l.p.x.q.s.p.txt == "i"