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

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

d = A("d")
g = B("g")
f = A("f")
b = A("b")
c = A("c")
h = A("h")

d.y = g
d.p = f
g.v = c
f.y = g
f.p = b
b.y = g
b.p = f
c.y = g
c.p = h
h.y = g
h.p = d
assert c.y.v.p.y.v.p.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.p: A = None
        self.txt = txt

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

d = A("d")
g = B("g")
f = A("f")
b = A("b")
c = A("c")
h = A("h")

d.y = g
d.p = f
g.v = c
f.y = g
f.p = b
b.y = g
b.p = f
c.y = g
c.p = h
h.y = g
h.p = d
assert c.y.v.p.y.v.p.txt == "h"