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

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

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

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

n = A("n")
a = B("a")
h = C("h")
d = D("d")
j = D("j")

n.q = d
n.r = a
a.o = n
a.x = n
a.q = j
h.v = j
h.r = a
d.p = j
d.x = a
j.p = d
j.x = a
assert h.r.o.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.r: B = None
        self.txt = txt

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

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

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

n = A("n")
a = B("a")
h = C("h")
d = D("d")
j = D("j")

n.q = d
n.r = a
a.o = n
a.x = n
a.q = j
h.v = j
h.r = a
d.p = j
d.x = a
j.p = d
j.x = a
assert h.r.o.q.p.txt == "j"