class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.r: A = 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.z: C = None
        self.txt = txt

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

a = A("a")
g = B("g")
b = C("b")
c = D("c")
h = C("h")
k = A("k")
l = A("l")

a.x = l
a.r = k
a.p = k
g.u = k
b.z = h
c.v = g
c.z = g
h.z = b
k.x = l
k.r = l
k.p = l
l.x = a
l.p = a
l.r = k
assert k.p.x.x.x.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.r: A = 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.z: C = None
        self.txt = txt

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

a = A("a")
g = B("g")
b = C("b")
c = D("c")
h = C("h")
k = A("k")
l = A("l")

a.x = l
a.r = k
a.p = k
g.u = k
b.z = h
c.v = g
c.z = g
h.z = b
k.x = l
k.r = l
k.p = l
l.x = a
l.p = a
l.r = k
assert k.p.x.x.x.p.txt == "k"