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

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

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

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

h = A("h")
f = B("f")
d = C("d")
e = D("e")

h.o = f
h.x = f
f.p = h
f.o = e
d.t = h
e.t = d
e.x = f
e.y = f
e.u = h
assert d.t.o.p.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.x: B = None
        self.txt = txt

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

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

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

h = A("h")
f = B("f")
d = C("d")
e = D("e")

h.o = f
h.x = f
f.p = h
f.o = e
d.t = h
e.t = d
e.x = f
e.y = f
e.u = h
assert d.t.o.p.txt == "h"