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

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

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

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

h = A("h")
n = B("n")
g = C("g")
e = D("e")

h.x = n
h.p = g
n.v = h
n.p = e
g.o = n
g.x = h
g.v = e
e.p = g
e.q = h
assert g.x.x.v.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.p: C = None
        self.txt = txt

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

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

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

h = A("h")
n = B("n")
g = C("g")
e = D("e")

h.x = n
h.p = g
n.v = h
n.p = e
g.o = n
g.x = h
g.v = e
e.p = g
e.q = h
assert g.x.x.v.p.txt == "g"