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

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

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

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

l = A("l")
d = B("d")
n = C("n")
c = D("c")
j = A("j")

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

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

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

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

l = A("l")
d = B("d")
n = C("n")
c = D("c")
j = A("j")

l.x = j
l.s = j
l.p = d
d.x = c
d.p = n
d.t = n
n.x = c
c.r = j
c.x = l
j.x = l
j.s = l
j.p = d
assert n.x.x.p.p.x.txt == "c"