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

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

k = A("k")
j = B("j")
d = B("d")
l = A("l")

k.p = j
k.y = l
j.v = l
j.y = d
d.v = l
d.y = j
l.p = j
l.y = k
assert k.p.y.v.y.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.y: A = None
        self.txt = txt

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

k = A("k")
j = B("j")
d = B("d")
l = A("l")

k.p = j
k.y = l
j.v = l
j.y = d
d.v = l
d.y = j
l.p = j
l.y = k
assert k.p.y.v.y.txt == "k"