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

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

n = A("n")
d = B("d")
e = A("e")
k = A("k")
j = A("j")
f = A("f")
h = B("h")
l = A("l")

n.x = e
n.p = e
d.x = h
d.r = h
e.x = j
e.p = l
k.x = f
k.p = e
j.x = n
j.p = e
f.x = e
f.p = j
h.x = d
h.r = d
l.x = j
l.p = n
assert k.p.p.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.p: A = None
        self.txt = txt

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

n = A("n")
d = B("d")
e = A("e")
k = A("k")
j = A("j")
f = A("f")
h = B("h")
l = A("l")

n.x = e
n.p = e
d.x = h
d.r = h
e.x = j
e.p = l
k.x = f
k.p = e
j.x = n
j.p = e
f.x = e
f.p = j
h.x = d
h.r = d
l.x = j
l.p = n
assert k.p.p.x.txt == "j"