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

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

l = A("l")
b = B("b")
j = A("j")
c = A("c")
k = B("k")
m = B("m")

l.v = c
l.x = c
b.p = j
j.v = c
j.x = l
c.v = j
c.x = l
k.p = j
m.p = l
assert k.p.x.x.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.x: A = None
        self.txt = txt

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

l = A("l")
b = B("b")
j = A("j")
c = A("c")
k = B("k")
m = B("m")

l.v = c
l.x = c
b.p = j
j.v = c
j.x = l
c.v = j
c.x = l
k.p = j
m.p = l
assert k.p.x.x.v.v.txt == "c"