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

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

k = A("k")
m = B("m")
h = A("h")
g = B("g")
j = A("j")
n = B("n")

k.r = m
m.p = j
h.r = m
g.p = k
j.r = m
n.p = h
assert g.p.r.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

k = A("k")
m = B("m")
h = A("h")
g = B("g")
j = A("j")
n = B("n")

k.r = m
m.p = j
h.r = m
g.p = k
j.r = m
n.p = h
assert g.p.r.p.r.txt == "m"