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

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

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

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

c = A("c")
m = B("m")
a = C("a")
h = D("h")
k = D("k")

c.o = k
c.y = a
m.t = a
m.u = k
a.p = c
h.x = m
k.x = m
assert k.x.u.x.t.txt == "
class A:
    def __init__(self, txt: str):
        self.o: D = None
        self.y: C = None
        self.txt = txt

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

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

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

c = A("c")
m = B("m")
a = C("a")
h = D("h")
k = D("k")

c.o = k
c.y = a
m.t = a
m.u = k
a.p = c
h.x = m
k.x = m
assert k.x.u.x.t.txt == "a"