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

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

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

class D:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

l = A("l")
h = B("h")
c = C("c")
j = D("j")
n = D("n")
k = D("k")

l.p = c
l.v = k
h.v = l
h.x = l
h.w = n
h.u = k
c.z = n
j.r = l
n.r = l
k.r = l
assert h.u.r.p.z.r.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.v: D = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

l = A("l")
h = B("h")
c = C("c")
j = D("j")
n = D("n")
k = D("k")

l.p = c
l.v = k
h.v = l
h.x = l
h.w = n
h.u = k
c.z = n
j.r = l
n.r = l
k.r = l
assert h.u.r.p.z.r.txt == "l"