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

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

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

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

f = A("f")
c = B("c")
h = C("h")
n = D("n")

f.p = h
c.o = n
c.q = h
h.p = c
h.y = c
h.s = n
h.u = f
n.p = f
n.x = c
assert n.x.q.u.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

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

f = A("f")
c = B("c")
h = C("h")
n = D("n")

f.p = h
c.o = n
c.q = h
h.p = c
h.y = c
h.s = n
h.u = f
n.p = f
n.x = c
assert n.x.q.u.p.txt == "h"