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

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

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

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

f = A("f")
h = B("h")
k = C("k")
n = D("n")
l = B("l")
m = B("m")
a = D("a")

f.x = k
f.u = n
h.u = f
h.x = k
k.q = m
n.t = l
l.u = f
l.x = k
m.u = f
m.x = k
a.t = m
assert h.x.q.u.x.q.u.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.u: D = None
        self.txt = txt

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

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

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

f = A("f")
h = B("h")
k = C("k")
n = D("n")
l = B("l")
m = B("m")
a = D("a")

f.x = k
f.u = n
h.u = f
h.x = k
k.q = m
n.t = l
l.u = f
l.x = k
m.u = f
m.x = k
a.t = m
assert h.x.q.u.x.q.u.txt == "f"