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

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

a = A("a")
e = B("e")
k = A("k")
f = B("f")
h = B("h")

a.t = k
a.y = f
e.p = a
k.t = a
k.y = h
f.p = a
h.p = k
assert k.y.p.y.p.y.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.y: B = None
        self.txt = txt

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

a = A("a")
e = B("e")
k = A("k")
f = B("f")
h = B("h")

a.t = k
a.y = f
e.p = a
k.t = a
k.y = h
f.p = a
h.p = k
assert k.y.p.y.p.y.txt == "h"