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

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

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

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

m = A("m")
j = B("j")
b = C("b")
h = D("h")
d = A("d")
k = B("k")

m.x = j
m.p = d
j.u = d
b.p = d
b.x = d
b.t = k
b.v = h
h.q = b
h.x = b
h.v = m
d.x = k
d.p = m
k.u = m
assert k.u.p.p.x.u.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.p: A = None
        self.txt = txt

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

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

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

m = A("m")
j = B("j")
b = C("b")
h = D("h")
d = A("d")
k = B("k")

m.x = j
m.p = d
j.u = d
b.p = d
b.x = d
b.t = k
b.v = h
h.q = b
h.x = b
h.v = m
d.x = k
d.p = m
k.u = m
assert k.u.p.p.x.u.p.txt == "m"