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

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

h = A("h")
f = B("f")
l = A("l")
c = B("c")

h.p = l
f.v = c
l.p = h
c.v = f
assert f.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

h = A("h")
f = B("f")
l = A("l")
c = B("c")

h.p = l
f.v = c
l.p = h
c.v = f
assert f.v.v.v.txt == "c"